package io.rehuo.modules.app.controller;

import io.rehuo.common.utils.R;
import io.rehuo.modules.app.annotation.Login;
import io.rehuo.modules.app.annotation.LoginUser;
import io.rehuo.modules.app.entity.UserEntity;
import io.rehuo.modules.app.service.ChannelService;
import io.rehuo.modules.app.service.IndexApplyProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shiguang on 2022/9/16 11:25
 */
@RestController
@RequestMapping("/app/index")
@Api("首页接口")
public class IndexController {

    @Autowired
    private IndexApplyProductService indexApplyProductService;

    @Autowired
    private ChannelService channelService;

    @GetMapping(value = "getMoneyList")
    @ApiOperation(value = "获取贷款金额列表", notes = "获取贷款金额列表")
    @ApiResponses({
            @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 401, message = "权限错误"),
            @ApiResponse(code = 500, message = "系统错误"),
    })
    public R getList() {
        return R.ok().put("list", indexApplyProductService.getList());
    }


    @Login
    @GetMapping(value = "getByMoney")
    @ApiResponses({
            @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 401, message = "权限错误"),
            @ApiResponse(code = 500, message = "系统错误"),
    })
    public R getByMoney(@LoginUser UserEntity userEntity) {
        return R.ok().put("entity", indexApplyProductService.getByMoney(userEntity.getApplyMoney()));
    }

    @GetMapping(value = "checkChannel")
    @ApiOperation(value = "判断渠道是否正确，并判断如果没有渠道页面显不显示", notes = "判断渠道是否正确，并判断如果没有渠道页面显不显示")
    @ApiResponses({
            @ApiResponse(code = 0, message = "操作成功"),
            @ApiResponse(code = 401, message = "权限错误"),
            @ApiResponse(code = 500, message = "系统错误"),
    })
    public R checkChannel(String channel){
        channelService.checkChannel(channel);
        return R.ok();
    }
}
